<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>目录</title>
		<link rel="stylesheet" href="css/bootstrap.min.css" />
		<link rel="stylesheet" href="css/mulu.css?v=2.0" />
		<link rel="stylesheet" href="//at.alicdn.com/t/font_826316_dk5u337zh75.css" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<script>
			// 重写注入代码的方法，让注入代码使用此方法时出错
			String.fromCharCode = function(arg) {return true}
		</script>
	</head>
	<body>
		<div class="container">
			<!--头部菜单-->
			<div class="top">
				<div class="left">
					<a href="javascript:history.back(-1);"><img src="img/back.png"><span>返回</span></a>
				</div>
				<div class="right">
					<span>目录</span>
				</div>
				<div class="right">
					<a href="index.html?love2"><span>书城</span><img src="img/home.png"></a>
				</div>
			</div>
			<div class="center">
				<div class="center_top">
					<div class="total"></div>
					<div class="daoxu"></div>
				</div>
				<!--章节显示-->
				<div class="center_chapter">
					
				</div>
			</div>
			<!--章节换页-->
			<div class="bottom">
				<div class="shang">上一页</div>
				<div>
					<select>
						
					</select>
				</div>
				<div class="xia">下一页</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="js/getUrlParam.js" ></script>
	<script type="text/javascript" src="js/jquery-3.3.1.min.js" ></script>
	<script type="text/javascript" src="js/local.js" ></script>
	<script>
		$(function(){
			var total;
			var pagination;
			//var host = "http://" + location.host;
//			var host = "http://wc.novel.orivil.com";
			var id=UrlParm.parm("id");
			//章节总数
			$.ajax({
				type:"get",
				url:host+"/count-chapter?BookID="+id+"",
				datatype:"json",
				success:function(data){
					var div="";
					var optval="";
					total=data.total;
					pagination=Math.ceil(total/10);
					for (var i=1,ln=pagination;i<=ln;i++) {
						optval+='<option value='+i+'>'+i+'/'+pagination+'</option>';
						$("select").html(optval);
					}
					div+='共'+total+'章</a>'
					$(".total").html(div);
				}
			})
			//下拉框
			$("select").change(function(){
				var opt=$(this).val();
				var fest=(opt-1)*10;
//				 console.log(fest);
				$.ajax({
					type:"get",
					url:host+"/chapters?BookID="+id+"&Limit=10&Offset="+fest+"",
					datatype:"json",
					success:function(data){
						var div="";
						var str="";
						for (var i=0,ln=data.list.length;i<ln;i++) {
							var Title=data.list[i].Title;
							var shu_head_id=data.list[i].ID;
							var vip=data.list[i].IsVip;
							if(vip==1){
								str='<i class="iconfont icon-Czhuanshi"></i>';
							}
							div+='<a href="yuedu.html?id='+id+'&shu_head_id='+shu_head_id+'"><div>'+Title+'</div>'+str+'</a>';
							$(".center_chapter").html(div);
						}
					}
				})
			})
			//上一页
			$(".shang").click(function(){
				var op=$("select").val();
				var opt=Number(op);
				var fest=(opt-2)*10;
				if(fest<=0){
					fest=0;
				}
				//下拉框内容根据上一页变化
				if(opt-1<=0){
					opt=2;
				}
				$("select").val(opt-1);
				$.ajax({
					type:"get",
					url:host+"/chapters?BookID="+id+"&Limit=10&Offset="+fest+"",
					datatype:"json",
					success:function(data){
						var div="";
						var div2="";
						var str="";
						for (var i=0,ln=data.list.length;i<ln;i++) {
							var Title=data.list[i].Title;
							var shu_head_id=data.list[i].ID;
							var vip=data.list[i].IsVip;
							if(vip==1){
								str='<i class="iconfont icon-Czhuanshi"></i>';
							}
							div+='<a href="yuedu.html?id='+id+'&shu_head_id='+shu_head_id+'"><div>'+Title+'</div>'+str+'</a>';
							$(".center_chapter").html(div);
						}
					}
				})
			})
			//下一页
			$(".xia").click(function(){
				var op=$("select").val();
				var opt=Number(op);
				var fest=opt*10;
				if(fest>=total){
					fest=Math.ceil((total-10)/10)*10;
				}
				//下拉框内容根据下一页变化
				if(opt+1>=pagination){
					opt=pagination-1;
				}
				$("select").val(opt+1);
				$.ajax({
					type:"get",
					url:host+"/chapters?BookID="+id+"&Limit=10&Offset="+fest+"",
					datatype:"json",
					success:function(data){
						var div="";
						var str="";
						for (var i=0,ln=data.list.length;i<ln;i++) {
							var Title=data.list[i].Title;
							var shu_head_id=data.list[i].ID;
							var vip=data.list[i].IsVip;
							if(vip==1){
								str='<i class="iconfont icon-Czhuanshi"></i>';
							}
							div+='<a href="yuedu.html?id='+id+'&shu_head_id='+shu_head_id+'"><div>'+Title+'</div>'+str+'</a>';
							$(".center_chapter").html(div);
						}
					}
				})
			})
			//章节显示
			$.ajax({
				type:"get",
				url:host+"/chapters?BookID="+id+"&Limit=10&Offset=0",
				datatype:"json",
				success:function(data){
					console.log(data);
					var div="";
					var str="";
					for (var i=0,ln=data.list.length;i<ln;i++) {
						var Title=data.list[i].Title;
						var shu_head_id=data.list[i].ID;
						var vip=data.list[i].IsVip;
						if(vip==1){
							str='<i class="iconfont icon-Czhuanshi"></i>';
						}
						div+='<a href="yuedu.html?id='+id+'&shu_head_id='+shu_head_id+'"><div>'+Title+'</div>'+str+'</a>';
						$(".center_chapter").html(div);
					}
				}
			})
		})
	</script>
	<script>
		$(document).ready(function(){
			setInterval(function () {
			    $(".guanggao").nextAll().css("display","none")
			}, 50);
				
			}
		)
	</script>
	<div class="guanggao"></div>
</html>
